<template>
  <!-- 用户管理————用户模式 -->
  <div id="userManage">
    <!-- <Breadcrumb content="用户模式" ischildren="false" /> -->
    <Splitpanes class="area">
      <Pane :size="(660 / conWidth) * 100">
        <vxe-toolbar perfect>
          <template #buttons>
            <vxe-input v-model="form.searchValue" type="search" clearable class="vxeInputSearch" placeholder="关键字查询" @keyup="keyupEnter" @clear="findUserList" @search-click="handleSearch(form.searchValue)"></vxe-input>

            <vxe-button type="text" class="button-blue" icon="vxe-icon-refresh" content="刷新" :loading="showLoading" @click="findUserList"></vxe-button>

            <vxe-button type="text" icon="vxe-icon-save" class="button-blue" content="保存" :loading="saveLoading" @click="saveList"></vxe-button>

            <vxe-button type="text" icon="vxe-icon-delete" class="button-red" content="删除" @click="handleDelete"></vxe-button>

            <vxe-button type="text" icon="vxe-icon-refresh" class="button-blue" content="重置密码" @click="resetPassword"></vxe-button>

            <!--暂时先隐藏，导入用户功能暂时无法测试  -->
            <!-- <vxe-button type="text" icon="vxe-icon-sort" class="button-blue" content="导入用户" :loading="importUserLoading" @click="getEmployeeList()"></vxe-button> -->
          </template>
        </vxe-toolbar>

        <div class="leftTable">
          <vxe-table ref="userTable" border="inner" class="mytable-scrollbar" :loading="showLoading" height="auto" :data="userList" :expand-config="{ expandAll: true, reserve: true }" @current-change="userRowClick" :row-config="{ isCurrent: true, isHover: true }" :keyboard-config="{
              isArrow: true,
              isTab: true,
              isEdit: true
            }" :edit-config="{ trigger: 'dblclick', mode: 'row', showStatus: true }" resizable show-overflow keep-source>
            <vxe-column type="checkbox" width="30px" align="center"></vxe-column>
            <vxe-column type="seq" title="序号" width="35px" align="center"></vxe-column>
            <vxe-column field="username" title="用户名" width="120px" :edit-render="{}">
              <template #edit="{ row }">
                <vxe-input v-model="row.username" type="text"></vxe-input>
              </template>
            </vxe-column>

            <vxe-column field="realname" title="名字" width="100px" :edit-render="{}">
              <template #edit="{ row, rowIndex, column }">
                <vxe-input v-model="row.realname" type="text" @keydown.enter="enterEvent(row, rowIndex, column)"></vxe-input>
              </template>
            </vxe-column>

            <vxe-column field="tel" title="电话" width="120px" :edit-render="{}">
              <template #edit="{ row, rowIndex, column }">
                <vxe-input v-model="row.tel" type="text" @keydown.enter="enterEvent(row, rowIndex, column)"></vxe-input>
              </template>
            </vxe-column>

            <vxe-column field="email" title="邮箱" min-width="130px" :edit-render="{}">
              <template #edit="{ row, rowIndex, column }">
                <vxe-input v-model="row.email" type="text" @keydown.enter="enterEvent(row, rowIndex, column)"></vxe-input>
              </template>
            </vxe-column>
            <vxe-column field="enable" title="是否启用" width="80" align="center" checked-value="1" unchecked-value="0">
              <template #default="{ row }">
                <vxe-checkbox v-model="row.enable" checked-value="1" unchecked-value="0"></vxe-checkbox>
                <!-- <el-checkbox v-model="row.enable" true-label="1" false-label="0" /> -->
              </template>
            </vxe-column>
          </vxe-table>
        </div>
        <!-- 分页 -->
        <vxe-pager align="left" size="mini" min-height="32px" height="32px" :current-page.sync="page.currentPage" :page-size.sync="page.pageSize" :total="page.totalResult" :layouts="['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total']" @page-change="handleSizeChange($event)"></vxe-pager>

        <el-dialog title="重置密码" :show-close="false" v-model="resetPsdModal" append-to-body :close-on-click-modal="false" style="height: 300px; width: 500px">
          <el-form ref="formPwdRef" :rules="formPwdRule" :model="formPwd" label-width="100px" class="form-input-m" :inline-message="true">
            <!-- <el-form-item prop="oldPassword" label="原密码">
              <el-input required v-model="formPwd.oldPassword" type="text" placeholder="请输入原密码"></el-input>
            </el-form-item> -->
            <el-form-item prop="newPassword" label="新密码">
              <el-input required v-model="formPwd.newPassword" type="text" placeholder="请输入新密码"></el-input>
            </el-form-item>
            <el-form-item prop="repeatPassword" label="重复密码">
              <el-input required v-model="formPwd.repeatPassword" type="text" placeholder="请输入重复密码"></el-input>
            </el-form-item>
          </el-form>

          <div class="dialog-footer flex right justify-end" style="margin-top: 10px">
            <el-button type="primary" @click="saveNewPassword()">提交</el-button>
            <el-button type="primary" @click="hidePsdModal()">取消</el-button>
          </div>
        </el-dialog>

        <!-- 导入用户  -->
        <vxe-modal v-model="employeeModal">
          <template #default>
            <el-scrollbar height="90%">
              <div class="importUser">
                <vxe-table :loading="importUserLoading" border="inner" ref="employeeTable" :data="employeeList" :expand-config="{ expandAll: true, reserve: true }" @current-change="userRowClick" :row-config="{ isCurrent: true, isHover: true }" :edit-config="{ trigger: 'dblclick', mode: 'row', showStatus: true }" resizable show-overflow keep-source>
                  <vxe-column type="checkbox" width="50px" align="center"></vxe-column>
                  <vxe-column type="seq" title="序号" width="50px" align="center"></vxe-column>
                  <vxe-column field="name" title="员工名称" width="400px"></vxe-column>
                  <vxe-column field="code" title="员工编码"></vxe-column>
                </vxe-table>
              </div>
            </el-scrollbar>
            <div class="flex right justify-end importUserButton">
              <vxe-button type="text" status="primary" icon="vxe-icon-add" content="添加" @click="importEmployee()"></vxe-button>
            </div>
          </template>
        </vxe-modal>
      </Pane>

      <!-- 中间用户基本信息 -->
      <Pane :size="(600 / conWidth) * 100" :height="conHeight">
        <div class="toolbartitle">基本信息</div>
        <el-form ref="userForm" :model="form" :rules="userFormRule" class="form-input-m" label-width="90px" v-loading="showLoading" inline-message>
          <el-form-item label="员工编号" prop="hisEmployeeCode">
            <SelectDataList ref="employeeSelectRef" :url="'/api/sys/hisEmployee/getEmployeePageList'" :displayField="[
                { title: '编号', props: 'code' }, //列标题
                { title: '名称', props: 'name' }
              ]" :searchParam="{
                //seachValue: form.hisEmployeeCode
              }" :inputKeyName="'seachValue'" :isPage="true" :title="'点击选择员工'" @selectDataRow="SelectRowClick" @clearValue="clearValueHandler" @sliceValue="sliceHandler" v-model="form.hisEmployeeCode" />
          </el-form-item>

          <el-form-item label="用户名" prop="username">
            <el-input v-model="form.username" placeholder="请输入用户名" clearable></el-input>
          </el-form-item>

          <el-form-item label="名字" prop="realname">
            <el-input v-model="form.realname" @change="autoInputCode" placeholder="请输入名字" clearable></el-input>
          </el-form-item>

          <el-form-item label="用户模式" prop="userMode">
            <el-select v-model="form.userMode" class="m-2" placeholder="请选择用户模式" filterable style="width: 200px">
              <el-option v-for="item in modeOptions" :key="item.modeCode" :label="item.modeName" :value="item.modeCode" />
            </el-select>
          </el-form-item>

          <el-form-item label="电话" prop="tel">
            <el-input v-model="form.tel" placeholder="请输入电话" clearable></el-input>
          </el-form-item>

          <el-form-item label="邮箱" prop="email">
            <el-input v-model="form.email" placeholder="请输入邮箱" clearable></el-input>
          </el-form-item>
          <el-form-item label="授权码" prop="empowerNum">
            <el-input v-model="form.empowerNum" placeholder="请输入授权码" type="password" clearable></el-input>
          </el-form-item>
          <el-form-item label="CA序列号" prop="initializer">
            <el-input v-model="form.initializer" placeholder="请输入CA序列号" clearable></el-input>
            <vxe-button type="text" class="button-blue" @click="getCainit">获取CA序列号</vxe-button>
          </el-form-item>
          <el-form-item label="助记符" prop="inputCode">
            <el-input v-model="form.inputCode" placeholder="请输入助记符" clearable></el-input>
          </el-form-item>
          <el-form-item label="所属机构" prop="orgId">
            <el-select v-model="form.orgId" placeholder="请选择" ref="selectOrgRef" filterable style="width: 200px">
              <el-option hidden :value="form.orgId ? form.orgId : ''" :label="form.orgName"></el-option>
              <el-tree filterable :data="orgList" :props="defaultProps" :expand-on-click-node="false" :default-expand-all="true" @node-click="handleOrgNodeClick" highlight-current ref="orgTreeRef" node-key="id" class="tools-tree"></el-tree>
            </el-select>

            <el-select v-model="form.deptId" placeholder="请选择" @clear="handleDeptClear" ref="selectDeptRef" clearable style="margin-left: 5px; width: 200px" filterable>
              <el-option hidden :value="form.deptId ? form.deptId : ''" :label="form.deptName"></el-option>
              <el-tree filterable :data="deptList" :props="defaultProps" :expand-on-click-node="false" :default-expand-all="true" @node-click="handleDeptNodeClick" highlight-current ref="deptTreeRef" node-key="id" class="tools-tree"></el-tree>
            </el-select>
          </el-form-item>
          <el-row>
            <el-col :span="8">
              <el-form-item label="是否启用" prop="isActive">
                <el-switch v-model="form.enable" inline-prompt active-text="是" inactive-text="否" active-value="1" inactive-value="0"></el-switch>
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="" label-width="0" prop="isTestDoctor">
                <el-checkbox v-model="form.isTestDoctor" label="是否检验医师" size="small" class="spec-checkbox" :true-label="1" :false-label="0" :true-value="1" :false-value="0" @change="saveUserInfo" />
              </el-form-item>
            </el-col>
            <el-col :span="8">
              <el-form-item label="" label-width="0" prop="isChkDoctor">
                <el-checkbox v-model="form.isChkDoctor" label="是否审核医师" size="small" class="spec-checkbox" :true-label="1" :false-label="0" :true-value="1" :false-value="0" @change="saveUserInfo" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-form-item label="用户角色" prop="roles" v-loading="showLoading">
            <el-checkbox-group v-model="checkRoles.arr" @change="checkboxs_change">
              <el-checkbox v-for="role in roleList" :label="role.id" :key="role.id" border class="min-width-checkbox">
                {{ role.roleName }}
              </el-checkbox>
            </el-checkbox-group>
          </el-form-item>

          <el-form-item class="form-footer">
            <template #default>
              <el-button type="primary" @click="addUser">新建</el-button>
              <el-button type="primary" v-loading="saveLoading" @click="save('userForm')">保存</el-button>
              <el-button type="primary" @click="getDifferenceSetRoles()" :loading="rolesPermissionDialog">获取角色外权限</el-button>
              <el-button type="primary" @click="signatureClick">电子签名</el-button>
              <el-button type="default" @click="resetForm(currentUser)">重置</el-button>
            </template>
          </el-form-item>
        </el-form>

        <!-- 角色外权限  -->
        <el-dialog title="角色外权限" v-model="differenceSetDialog">
          <template #default>
            <el-scrollbar height="400px">
              <div class="paneBox" v-if="uncludeModules.length !== 0" v-loading="rolesPermissionDialog">
                <el-card class="box-card" v-for="(item, index) in uncludeModules" :key="index" shadow="hover">
                  <template #header>
                    <div class="card-header">
                      <!-- 模块名 -->
                      <span class="cardtext">{{ item.name }}</span>
                    </div>
                  </template>

                  <div class="detailBox text">
                    <div class="menuBox">
                      <div class="tagtitle1">菜单权限</div>
                      <div v-for="(m, mindex) in uncludeModuleMenuMap[item.id]" :key="mindex" style="display: inline-block">
                        <!-- 一级菜单 (没有子集时自己要加复选框) -->
                        <el-checkbox-group v-if="m.children.length === 0" v-model="checkMenuRoles.arr" @change="checkMenuboxs_change">
                          <div class="checkItem">
                            <el-checkbox :key="m.id" :label="m.title" type="success" class="margin-left-xs tagBox tagboxborder dialogOnlyFirstMenu"> </el-checkbox>
                          </div>
                        </el-checkbox-group>

                        <!-- 一级菜单(有子集时 子集加复选框) -->
                        <div v-else>
                          <el-tag class="margin-left-xs tagBox tagboxborder DialogFirstTag" effect="plain" type="success">
                            {{ m.title }}
                          </el-tag>

                          <!-- 二级菜单 -->
                          <div class="twoMenuTag twoMenuTagDialog" v-for="(sonm, sonmindex) in m.children" :key="sonmindex">
                            <el-checkbox-group v-model="checkMenuRoles.arr" @change="checkMenuboxs_change">
                              <div class="checkItem">
                                <el-checkbox :key="sonm.id" :label="sonm.id" type="info" class="margin-left-xs tagBox DiaTwoboxBorder twomenutagbgc"> {{ sonm.title }}</el-checkbox>
                              </div>
                            </el-checkbox-group>
                          </div>
                        </div>
                      </div>
                    </div>

                    <!-- 功能(只有一级) -->
                    <div class="pointBox">
                      <div class="tagtitle2">功能权限</div>
                      <el-checkbox-group v-model="checkPointsRoles.arr" @change="checkPointsboxs_change">
                        <div class="checkItem">
                          <el-checkbox v-for="(p, pindex) in uncludeModulePointCodeMap[item.id]" :key="p.id" :label="p.id" class="margin-left-xs margin-bottom-sm tagBox1 tagboxborder pointSelectBox">
                            {{ p.title }}
                          </el-checkbox>
                        </div>
                      </el-checkbox-group>
                    </div>
                  </div>
                </el-card>
              </div>
              <el-empty :image-size="200" v-else style="height: calc(100% - 40px)" />
              <!-- <NoData :msg="msg"/> -->
            </el-scrollbar>
            <div class="dialog-footer right flex justify-end" style="margin-top: 10px">
              <el-button @click="differenceSetDialog = false">取 消</el-button>
              <el-button type="primary" @click="saveDifferenceData()">确 定</el-button>
            </div>
          </template>
        </el-dialog>
      </Pane>

      <!--  右侧详细信息 -->
      <Pane class="rightDetail">
        <div class="rightContent">
          <el-tabs type="border-card">
            <el-tab-pane label="功能菜单">
              <div class="toolbartitle">权限详情</div>
              <el-scrollbar style="height: calc(100% - 40px)">
                <div class="paneBox" v-loading="showLoading" v-if="modules.length !== 0">
                  <el-card class="box-card" v-for="(item, index) in modules" :key="item.id" shadow="hover">
                    <template #header>
                      <div class="card-header">
                        <span class="cardtext">{{ item.name }}</span>
                      </div>
                    </template>
                    <div class="detailBox text">
                      <div class="menuBox">
                        <div class="tagtitle1">菜单权限</div>
                        <div v-for="(m, mindex) in moduleMenuMap[item.id]" :key="mindex" style="display: inline-block">
                          <!-- 一级菜单 -->
                          <el-tag class="margin-left-xs tagBox tagboxborder" effect="plain" type="success">{{ m.title }}
                            <el-icon class="tagicon" @click="handleClose(m)">
                              <Close style="color: #27b46b" />
                            </el-icon>
                          </el-tag>
                          <!-- 二级菜单 -->
                          <div class="twoMenuTag" v-for="(sonm, sonmindex) in m.children" :key="sonmindex">
                            <el-tag class="margin-left-xs margin-bottom-sm tagBox twomenutagbgc" type="info" effect="plain" style="margin-left: -5px">{{ sonm.title }}
                              <el-icon class="tagicon" @click="handleClose(sonm)">
                                <Close style="color: #9daed2" />
                              </el-icon>
                            </el-tag>
                          </div>
                        </div>
                      </div>
                      <div class="pointBox">
                        <div class="tagtitle2">功能权限</div>
                        <div>
                          <el-tag class="margin-left-xs margin-bottom-sm tagBox1 tagboxborder pointSelectBox" effect="plain" type="success" v-for="(p, pindex) in modulePointCodeMap[item.id]" :key="pindex">{{ p.title }}
                            <span>
                              <el-icon class="tagicon" @click="handleClose(p)">
                                <Close style="color: #eabe7e" />
                              </el-icon> </span></el-tag>
                        </div>
                      </div>
                    </div>
                  </el-card>
                </div>
                <el-empty :image-size="200" v-else style="height: 100%" />
                <!-- <NoData :msg="msg"  v-else/> -->
              </el-scrollbar>
            </el-tab-pane>
            <el-tab-pane label="报告单元">
              <el-scrollbar style="height: 100%">
                <div class="UnitBox">
                  <div class="allSelectedBtns">
                    <vxe-button status="primary" content="设置全选" @click="selectAllSelect"></vxe-button>
                    <vxe-button status="primary" content="取消全选" @click="clearAllSelect"></vxe-button>
                  </div>
                  <div>
                    <el-checkbox-group v-model="checkRptGroupList">
                      <el-checkbox border :label="p.rptGroupName" v-for="(p, pindex) in rptGroupList" :key="pindex" @change="rptGroupChange(p.id, $event)" />
                    </el-checkbox-group>
                  </div>
                </div>
              </el-scrollbar>
            </el-tab-pane>
            <el-tab-pane label="检验仪器">
              <el-scrollbar style="height: 100%">
                <div class="UnitBox">
                  <div class="allSelectedBtns">
                    <vxe-button status="primary" content="设置全选" @click="selectAllSelect1"></vxe-button>
                    <vxe-button status="primary" content="取消全选" @click="clearAllSelect1"></vxe-button>
                  </div>
                  <div>
                    <el-checkbox-group v-model="checkInstrSetupList">
                      <el-checkbox border :label="p.instrName" v-for="(p, pindex) in instrSetupList" :key="pindex" @change="instrSetupChange($event, p.id)" />
                    </el-checkbox-group>
                  </div>
                </div>
              </el-scrollbar>
            </el-tab-pane>
            <el-tab-pane label="授权科室">
              <vxe-toolbar perfect>
                <template #buttons>
                  <div class="smallToolTitle">授权科室</div>
                  <vxe-button type="text" class="button-blue" icon="vxe-icon-refresh" content="刷新" :loading="qloading" @click="findUserDepartmentList"></vxe-button>
                  <vxe-button type="text" class="button-blue" icon="vxe-icon-square-plus" content="添加" @click="addUserDepartDialog()"></vxe-button>
                  <vxe-button type="text" icon="vxe-icon-delete" class="button-red" content="删除" @click="handleUserDepartmentDelete"></vxe-button>
                </template>
              </vxe-toolbar>

              <div class="rightTable">
                <vxe-table ref="qcItemTableRef" class="mytable-scrollbar" border="inner" align="center" height="auto" :data="userDepartmentList" :loading="qloading" :row-config="{ isCurrent: true, isHover: true}" :column-config="{ resizable: true }" resizable show-overflow keep-source>
                  <vxe-column type="checkbox" width="30" align="center"></vxe-column>
                  <vxe-column field="deptCode" title="科室编码">
                    <template #edit="{ row }">
                      <vxe-input v-model="row.deptCode" type="text" width="100px"></vxe-input>
                    </template>
                  </vxe-column>

                  <vxe-column field="deptName" title="科室名字">
                    <template #edit="{ row, rowIndex, column }">
                      <vxe-input v-model="row.realname" type="text"></vxe-input>
                    </template>
                  </vxe-column>

                </vxe-table>
              </div>

              <el-dialog title="科室" :show-close="false" v-model="showDialog" append-to-body width="800px" :close-on-click-modal="false" destroy-on-close v-if="showDialog">
                <vxe-toolbar perfect>
                  <template #buttons>
                    <vxe-input style="width: 130px" v-model="searchDeptForm.searchValue" type="search" clearable class="vxeInputSearch" placeholder="关键字查询" @clear="findOrgDeptList2" @keyup="keyupDeptEnter" @search-click="findOrgDeptList2()"></vxe-input>
                    <vxe-button type="text" class="button-blue" content="查询" :loading="lloading" @click="findOrgDeptList2"></vxe-button>
                  </template>
                </vxe-toolbar>
                <div class="tableBody" style="height: 600px">
                  <vxe-table :data="orgDeptList" :loading="lloading" ref="labItemTableRef" class="mytable-scrollbar dialogTable" border height="520px" align="center" :row-config="{ keyField: 'id', isHover: true }" :column-config="{ resizable: true }" :checkbox-config="{
                  checkMethod: checCheckboxkMethod2,
                  visibleMethod: showCheckboxkMethod2
                }" resizable show-overflow keep-source>
                    <vxe-column title="序号" width="80">
                      <template #default="{ row, rowIndex, column }">
                        <span>{{ rowIndex + 1 }}</span>
                      </template>
                    </vxe-column>
                    <vxe-column type="checkbox" width="100px"></vxe-column>
                    <vxe-column field="code" title="科室编码" width="120px">
                      <template #edit="{ row }">
                        <vxe-input v-model="row.code" type="text"></vxe-input>
                      </template>
                    </vxe-column>

                    <vxe-column field="name" title="科室名字">
                      <template #edit="{ row, rowIndex, column }">
                        <vxe-input v-model="row.name" type="text"></vxe-input>
                      </template>
                    </vxe-column>

                  </vxe-table>

                  <div class="dialog-footer flex right justify-end">
                    <el-button type="primary" @click="saveBacthQcItem('qcItemTableRef')">确定</el-button>
                    <el-button @click="closeDialog('qcItemTableRef')">取消</el-button>
                  </div>
                </div>
              </el-dialog>

            </el-tab-pane>
            <el-tab-pane label="危急值对照科室">
              <vxe-toolbar perfect>
                <template #buttons>
                  <div class="smallToolTitle">对照科室</div>
                  <vxe-button type="text" class="button-blue" icon="vxe-icon-refresh" content="刷新" :loading="qloading" @click="findCriUserVsDeptList"></vxe-button>
                  <vxe-button type="text" class="button-blue" icon="vxe-icon-square-plus" content="添加" @click="addUserVsDeptDialog()"></vxe-button>
                  <vxe-button type="text" icon="vxe-icon-delete" class="button-red" content="删除" @click="handleUserVsDepartmentDelete"></vxe-button>
                </template>
              </vxe-toolbar>

              <div class="rightTable">
                <vxe-table ref="userVsDeptTable" class="mytable-scrollbar" border="inner" align="center" height="auto" :data="userVsDeptList" :loading="qloading" :row-config="{ isCurrent: true, isHover: true}" :column-config="{ resizable: true }" resizable show-overflow keep-source>
                  <vxe-column type="checkbox" width="30" align="center"></vxe-column>
                  <vxe-column field="deptCode" title="科室编码">
                    <template #edit="{ row }">
                      <vxe-input v-model="row.deptCode" type="text" width="100px"></vxe-input>
                    </template>
                  </vxe-column>

                  <vxe-column field="deptName" title="科室名字">
                    <template #edit="{ row, rowIndex, column }">
                      <vxe-input v-model="row.realname" type="text"></vxe-input>
                    </template>
                  </vxe-column>

                </vxe-table>
              </div>

              <el-dialog title="科室" :show-close="false" v-model="showUserVsDeptDialog" append-to-body width="800px" :close-on-click-modal="false" destroy-on-close v-if="showUserVsDeptDialog">
                <vxe-toolbar perfect>
                  <template #buttons>
                    <vxe-input style="width: 130px" v-model="searchDeptForm.searchValue" type="search" clearable class="vxeInputSearch" placeholder="关键字查询" @clear="findUserVsOrgDeptList" @keyup="keyupUserDeptEnter" @search-click="findUserVsOrgDeptList()"></vxe-input>
                    <vxe-button type="text" class="button-blue" content="查询" :loading="lloading" @click="findUserVsOrgDeptList"></vxe-button>
                  </template>
                </vxe-toolbar>
                <div class="tableBody" style="height: 600px">
                  <vxe-table :data="orgUserVsDeptList" :loading="lloading" ref="criUserVsDeptTableRef" class="mytable-scrollbar dialogTable" border height="520px" align="center" :row-config="{ keyField: 'id', isHover: true }" :column-config="{ resizable: true }" :checkbox-config="{
                  checkMethod: checCheckboxkMethod3,
                  visibleMethod: showCheckboxkMethod3,
                  checkRowKeys: defaultSelecteRowKeysByUser
                }" resizable show-overflow keep-source>
                    <vxe-column title="序号" width="80">
                      <template #default="{ row, rowIndex, column }">
                        <span>{{ rowIndex + 1 }}</span>
                      </template>
                    </vxe-column>
                    <vxe-column type="checkbox" width="100px"></vxe-column>
                    <vxe-column field="code" title="科室编码" width="120px">
                      <template #edit="{ row }">
                        <vxe-input v-model="row.code" type="text"></vxe-input>
                      </template>
                    </vxe-column>

                    <vxe-column field="name" title="科室名字">
                      <template #edit="{ row, rowIndex, column }">
                        <vxe-input v-model="row.name" type="text"></vxe-input>
                      </template>
                    </vxe-column>

                  </vxe-table>

                  <div class="dialog-footer flex right justify-end">
                    <el-button type="primary" @click="saveBacthUserVsDept('qcItemTableRef')">确定</el-button>
                    <el-button @click="closeUserVsDeptDialog('qcItemTableRef')">取消</el-button>
                  </div>
                </div>
              </el-dialog>

            </el-tab-pane>
          </el-tabs>
        </div>
      </Pane>
    </Splitpanes>
    <SignatureUser ref="signatureUserRef" />
  </div>
</template>

<script setup lang="ts">
// 引入组件区 ==========
import Breadcrumb from '@/components/Breadcrumb.vue';
import { ref, reactive, getCurrentInstance, onMounted } from 'vue';
import { pageSizes, validatePhoneTwo, validateEMail, IsEmpty } from '@/utils/common'; //导入工具函数
import { Splitpanes, Pane } from 'splitpanes';
import { AppStore } from '../../stores/store';
import SelectDataList from '@/components/SelectDataList.vue';
import { VXETable } from 'vxe-table';
import NoData from '@/components/NoData.vue'; //空状态
import SelectVxeGrid from '@/components/SelectDataGrid.vue';
import SignatureUser from './SignatureUser.vue';
import security from '@/utils/securityPlugin.js';

// 全局变量定义区 ==========
let msg = '暂无数据';
let { proxy }: any = getCurrentInstance();
let store = AppStore();

// 获取屏幕高度
let conHeight = ref((document.documentElement.clientHeight || document.body.clientHeight) - 148 + 'px');
// 获取屏幕宽度
let conWidth = ref(document.documentElement.clientWidth);
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage';
import LuckyExcelForm from '@/components/LuckyExcel.vue';
import type { ElInput, FormRules } from 'element-plus'; //提示信息
import { funBdsJsResult } from '@/utils/Expression';
import { objectEach } from 'xe-utils';

// 获取模块id
const moduleId = localStorage.getItem('moduleId');
// 功能点权限
let modulePoitPre = reactive([]);
// 通过权限获取功能点
let modulePointMap = store.userInfo.modulePointMap;
function getModulePointMap() {
  if (Object.keys(modulePointMap).includes(moduleId)) {
    modulePoitPre.push(...modulePointMap[moduleId]);
  }
}

let signatureUserRef = ref(null); /**电子签名组件对象 */

// 加载状态
let showLoading = ref(false); //左侧表格加载+上方刷新按钮+中间表单+右侧详情
let saveLoading = ref(false); //左侧保存+中间保存
let importUserLoading = ref(false); //导入用户加载状态
let rolesPermissionDialog = ref(false); //获取角色外权限弹框
let employeeModal = ref(false); // 导入用户列表弹框显示与否

// 条数/页
const PageSizeList = [10, 50, 100, 200, 500];

let page = reactive({
  currentPage: 1,
  pageSize: PageSizeList[1],
  totalResult: 0
});

let formPwdRef: any = ref(null);

let formPwdRule = {
  oldPassword: [
    {
      required: true,
      message: '请输入原密码',
      trigger: 'blur'
    },
    {
      min: 6,
      max: 20,
      message: '长度为6到20个字符',
      trigger: 'blur'
    }
  ],
  newPassword: [
    {
      required: true,
      message: '请输入新密码',
      trigger: 'blur'
    },
    {
      min: 3,
      max: 20,
      message: '长度为3到20个字符',
      trigger: 'blur'
    }
  ],
  repeatPassword: [
    {
      required: true,
      message: '请输入重复密码',
      trigger: 'blur'
    },
    {
      min: 3,
      max: 20,
      message: '长度为3到20个字符',
      trigger: 'blur'
    }
  ]
};

let userTable = ref(); //左侧用户表格ref
let userList: any = reactive([]); //左侧用户表格数据
let employeeList: any = reactive([]); //导入用户弹框表格数据
// 重置密码
let resetPsdModal = ref(false);
let formPwd: any = reactive({
  oldPassword: '', //原密码
  newPassword: '', //新密码
  repeatPassword: '' //确认密码
});

// 中间用户基本信息表单
let form = reactive({
  id: null,
  username: '',
  realname: '',
  userMode: '',
  password: '',
  tel: '',
  email: '',
  empowerNum: '',
  initializer: '',
  inputCode: '',
  enable: '1', //是否启用
  roles: [],
  orgName: '',
  orgId: '',
  deptId: '',
  deptName: '',
  hisEmployeeId: '', //用户员工
  hisEmployeeCode: '',
  searchValue: '',
  isTestDoctor: 0 /*是否检验医师* */,
  isChkDoctor: 0 /** 是否审核医师*/
});

// 中间用户基本信息校验
let userFormRule: any = {
  username: [
    {
      required: true,
      message: '请输入用户名',
      trigger: 'blur'
    },
    {
      min: 1,
      max: 256,
      message: '长度为1到256个字符',
      trigger: 'blur'
    },
    {
      message: '用户名只能为数字或英文字母',
      validator: proxy.validateUserName
    }
  ]
  // tel: [
  //   {
  //     required: true,
  //     message: '请输入电话',
  //     trigger: 'blur'
  //   },
  //   {
  //     validator: validatePhoneTwo,
  //     trigger: 'blur'
  //   }
  // ],
  // email: [
  //   {
  //     required: true,
  //     message: '请输入邮箱',
  //     trigger: 'blur'
  //   },
  //   {
  //     validator: validateEMail,
  //     trigger: 'change'
  //   }
  // ]
};

let orgList: any = reactive([]); //所有的组织机构
let deptList: any = reactive([]); //所有的部门
let defaultProps = {
  children: 'children',
  label: 'name'
};
let visibleOutReporter: any = ref(false);
let currentUser: any = reactive({}); //当前用户
let currentRowIndex = 0; //当前行索引

let roleList: any = reactive([]); //所有的角色列表数据
let roleNames: any = reactive([]);
let checkRoles: any = reactive({
  arr: []
}); //当前用户选中的角色列表数据

// 当前选中用户数据
let userInfo: any = reactive({
  id: '',
  userName: ''
});
// 模块对象
let modules: any = reactive([]);
// 模块菜单对象
let moduleMenuMap: any = reactive({});
// 模块功能点对象
let modulePointCodeMap: any = reactive({});
// 不获取不同角色弹框
let differenceSetDialog = ref(false);
// 角色外模块对象
let uncludeModules: any = reactive([]);
// 角色外模块菜单对象
let uncludeModuleMenuMap: any = reactive({});
// 角色外模块功能点对象
let uncludeModulePointCodeMap: any = reactive({});
// 角色外绑定菜单权限数组
let checkMenuRoles: any = reactive({
  arr: []
});
// 角色外绑定功能权限数组
let checkPointsRoles: any = reactive({
  arr: []
});

let modeOptions = reactive([]);
let rptGroupList = reactive([]);
let instrSetupList = reactive([]);
const checkRptGroupList = reactive([]);
const checkInstrSetupList = reactive([]);

let checkMap = reactive({});
let checkInstrSetUpMap = reactive({});

// 方法定义区 =============
// 页面加载时更新用户/角色列表
onMounted(() => {
  getModulePointMap();
  findUserList1(); //查找用户列表
  findRoleList(); //查找角色列表
  findOrgTree();
  getDictItemsList();
  findRptGroupList();
  findInstrSetUpList();
});

function rptGroupChange(rptGroupId: any, e: any) {
  if (!userInfo.id) {
    VxeMessage('请先保存用户基本信息，再分配报告单元权限', VxeNotifyType.error);
    return;
  }
  if (e) {
    const url = '/api/userRptGroup/addSysUserRptGroup';
    proxy.$http
      .post(url, { userId: userInfo.id, rptGroupId: rptGroupId })
      .then((res: any) => {
        if (res.status.code !== 1) {
          VxeMessage('添加报告单元失败！', VxeNotifyType.error);
        } else {
          checkRptGroupList.push(checkMap[rptGroupId]);
          VxeMessage('添加报告单元成功！', VxeNotifyType.success);
        }
      })
      .catch((err: any) => {
        VxeMessage(err, VxeNotifyType.error);
      });
  }
  if (!e) {
    const url = '/api/userRptGroup/deleteSysUserRptGroup';
    proxy.$http
      .post(url, { userId: userInfo.id, rptGroupId: rptGroupId })
      .then((res: any) => {
        if (res.status.code !== 1) {
          VxeMessage('删除报告单元失败！', VxeNotifyType.error);
        } else {
          let jj = checkRptGroupList.filter((item) => item != checkMap[rptGroupId]);
          checkRptGroupList.length = 0;
          checkRptGroupList.push(...jj);
          VxeMessage('删除报告单元成功！', VxeNotifyType.success);
        }
      })
      .catch((err: any) => {
        VxeMessage(err, VxeNotifyType.error);
      });
  }
}
// 获取所有报告单元
async function findRptGroupList() {
  const url = '/api/rptGroup/findRptGroup';
  await proxy.$http
    .get(url)
    .then((res: any) => {
      if (res.status.code !== 1) {
        VxeMessage(res.status.msg, VxeNotifyType.error);
      } else {
        rptGroupList.push(...res.data);
        checkMap = Object.fromEntries(rptGroupList.map((item) => [item.id, item.rptGroupName]));
      }
    })
    .catch((err: any) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}

// 获取用户下报告单元
function findCheckList() {
  checkRptGroupList.length = 0;
  const url = '/api/userRptGroup/findSysUserRptGroupList/' + userInfo.id;
  proxy.$http
    .get(url)
    .then((res: any) => {
      if (res.status.code !== 1) {
        VxeMessage(res.status.msg, VxeNotifyType.error);
      } else {
        let n = res.data.map((item) => {
          return checkMap[item.rptGroupId];
        });
        checkRptGroupList.push(...n);
      }
    })
    .catch((err: any) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}
// 添加或删除仪器权限
function instrSetupChange(e: any, instrSetupId: any) {
  if (!userInfo.id) {
    VxeMessage('请先保存用户基本信息，再分配检验仪器', VxeNotifyType.error);
    return;
  }
  if (e) {
    const url = '/api/userInstrSetup/addUserInstrSetUp';
    proxy.$http
      .post(url, { userId: userInfo.id, instrSetupId: instrSetupId })
      .then((res: any) => {
        if (res.status.code !== 1) {
          VxeMessage('添加仪器失败！', VxeNotifyType.error);
        } else {
          checkInstrSetupList.push(checkInstrSetUpMap[instrSetupId]);
        }
      })
      .catch((err: any) => {
        VxeMessage(err, VxeNotifyType.error);
      });
  } else {
    const url = '/api/userInstrSetup/deleteUserInstrSetUp';
    proxy.$http
      .post(url, { userId: userInfo.id, instrSetupId: instrSetupId })
      .then((res: any) => {
        if (res.status.code !== 1) {
          VxeMessage('删除仪器失败！', VxeNotifyType.error);
        } else {
          let jj = checkInstrSetupList.filter((item) => item != checkInstrSetUpMap[instrSetupId]);
          checkInstrSetupList.length = 0;
          checkInstrSetupList.push(...jj);
        }
      })
      .catch((err: any) => {
        VxeMessage(err, VxeNotifyType.error);
      });
  }
}

// 获取所有仪器
async function findInstrSetUpList() {
  const url = '/lis/instrSetup/findLabInstrSetupList';
  await proxy.$http
    .get(url)
    .then((res: any) => {
      if (res.status.code !== 1) {
        VxeMessage(res.status.msg, VxeNotifyType.error);
      } else {
        instrSetupList.push(...res.data);
        checkInstrSetUpMap = Object.fromEntries(instrSetupList.map((item) => [item.id, item.instrName]));
      }
    })
    .catch((err: any) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}

// 获取用户权限下的仪器
function findcheckInstrSetupList() {
  checkInstrSetupList.length = 0;
  const url = '/api/userInstrSetup/findSysUserInstrSetupList/' + userInfo.id;
  proxy.$http
    .get(url)
    .then((res: any) => {
      if (res.status.code !== 1) {
        VxeMessage(res.status.msg, VxeNotifyType.error);
      } else {
        let n = res.data.map((item) => {
          return checkInstrSetUpMap[item.instrSetupId];
        });
        checkInstrSetupList.push(...n);
      }
    })
    .catch((err: any) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}

// 获取字典
async function getDictItemsList() {
  const url = '/api/sys/basDictDetail/findDictDetailListByDictCodes';
  const dictTreeTypeItems: any = await proxy.$http.get(url, { params: { code: 'modeUrlDict' } });
  const itemClassType = dictTreeTypeItems.data.find((item) => item.code === 'modeUrlDict');
  modeOptions.push(...itemClassType.detailDataList);
}
//点击每页数量
function handleSizeChange({ type, currentPage, pageSize }) {
  if (type === 'size') {
    page.currentPage = 1;
  } else {
    page.currentPage = currentPage;
  }
  page.pageSize = pageSize;
  findUserList();
}

// 选中的角色改变
function checkboxs_change(value: any) {
  checkRoles.arr = value;
  modules.length = 0;
  if (form.id == '' || form.id == null || form.id == undefined) {
    checkBeforeSaveUser();
  } else {
    handleUserAuthDetails();
  }
}

function checkBeforeSaveUser() {
  // 新增用户
  const url = '/api/user/addUserInfo';
  const user = {
    username: form.username,
    realname: form.realname,
    userMode: form.userMode,
    orgId: form.orgId,
    deptId: form.deptId,
    tel: form.tel,
    email: form.email,
    inputCode: form.inputCode,
    empowerNum: form.empowerNum,
    initializer: form.initializer,
    roleIds: checkRoles.arr,
    enable: form.enable,
    hisEmployeeId: form.hisEmployeeId,
    hisEmployeeCode: form.hisEmployeeCode
  };
  proxy.$http
    .post(url, user)
    .then((res: any) => {
      if (res.status.code === 1) {
        userInfo.id = res.data.id;
        form.id = res.data.id;
        handleUserAuthDetails();
      }
    })
    .catch((err: any) => {
      VxeMessage('新增用户失败', VxeNotifyType.error);
    });
}
// 角色外绑定菜单权限数组事件
function checkMenuboxs_change(value: any) {
  checkMenuRoles.arr = value;
}
// 角色外绑定功能权限数组事件
function checkPointsboxs_change(value: any) {
  checkPointsRoles.arr = value;
}

// 右侧详情 图标删除
function handleClose(tag: any) {
  showLoading.value = true;
  const url = '/api/user/sysUserAuthDetail/deleteUserAuthById';
  // 如果有子孩子
  if (tag.children && tag.children.length !== 0) {
    VxeMessage('要删除的这一条数据下还有子数据，不可删除', VxeNotifyType.error);
  } else {
    let obj = {
      id: tag.creator,
      title: tag.title,
      username: userInfo.userName
    };
    proxy
      .$confirm('确定删除此条权限？', '提示', {
        cancelButtonClass: 'cancel-button',
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
      .then(() => {
        proxy.$http
          .post(url, obj)
          .then((res: any) => {
            if (res.data === 1) {
              modules.length = 0;
              getSysUserAuthdetailsByRoleIds();
              showLoading.value = false;
            }
          })
          .catch((err: any) => {
            showLoading.value = false;
            VxeMessage('删除用户详情数据失败', VxeNotifyType.error);
          });
      });
    showLoading.value = false;
  }
}

// 授权失败
function handleUserAuthDetails() {
  showLoading.value = true;
  if (checkRoles && checkRoles.arr && checkRoles.arr.length > 0) {
    const url = '/api/user/sysUserAuthDetail/handleUserAuthDetails';
    const handleObj = {
      userId: userInfo.id,
      roleIds: checkRoles.arr
    };
    modules.length = 0;
    proxy.$http
      .post(url, handleObj)
      .then((res: any) => {
        modules.push(...res.data.modules);
        moduleMenuMap = res.data.moduleMenuMap;
        modulePointCodeMap = res.data.modulePointCodeMap;
        showLoading.value = false;
      })
      .catch((err: any) => {
        showLoading.value = false;
        VxeMessage('授权失败！', VxeNotifyType.error);
      });
  }
  showLoading.value = false;
}

function getSysUserAuthdetailsByRoleIds() {
  // if (checkRoles && checkRoles.arr && checkRoles.arr.length > 0) {
  const url = '/api/user/sysUserAuthDetail/getSysUserAuthdetailsByRoleIds';
  const handelUserAuthParam = {
    userId: userInfo.id,
    roleIds: checkRoles.arr
  };
  modules.length = 0; //获取数据前清空数据，否则数据重复！

  proxy.$http
    .post(url, handelUserAuthParam)
    .then((res: any) => {
      modules.push(...res.data.modules);
      moduleMenuMap = res.data.moduleMenuMap;
      modulePointCodeMap = res.data.modulePointCodeMap;
    })
    .catch((err: any) => {
      VxeMessage('搜索用户列表失败', VxeNotifyType.error);
    });
  // }
}

function getDifferenceSetRoles() {
  rolesPermissionDialog.value = true; //加载状态
  differenceSetDialog.value = true;
  uncludeModules.length = 0;
  uncludeModuleMenuMap = {};
  checkMenuRoles.arr.length = 0;
  checkPointsRoles.arr.length = 0;
  uncludeModulePointCodeMap = {};
  if (checkRoles && checkRoles.arr && checkRoles.arr.length > 0) {
    const url = '/api/sys/sysUserAuthDiffer/getDifferenceSetRoles';
    const handleObj = {
      userId: userInfo.id,
      roleId: '',
      roleIds: checkRoles.arr
    };
    proxy.$http
      .post(url, handleObj)
      .then((res: any) => {
        uncludeModules.push(...res.data.modules);
        uncludeModuleMenuMap = res.data.moduleMenuMap;
        uncludeModulePointCodeMap = res.data.modulePointCodeMap;
        // rolesPermissionDialog.value= false
      })
      .catch((err: any) => {
        // rolesPermissionDialog.value= false
        VxeMessage('搜索用户列表失败', VxeNotifyType.error);
      });
  }
  rolesPermissionDialog.value = false;
}

function saveDifferenceData() {
  differenceSetDialog.value = false;
  const url = '/api/user/sysUserAuthDetail/addUserAuthDetails';
  const handleObj = {
    userId: userInfo.id,
    username: userInfo.userName,
    roleId: checkRoles.arr[0],
    roleName: roleNames[0],
    menus: checkMenuRoles.arr,
    points: checkPointsRoles.arr
  };
  if (handleObj.points.length !== 0 || handleObj.menus.length !== 0) {
    proxy.$http
      .put(url, handleObj)
      .then((res: any) => {
        modules.length = 0;
        getSysUserAuthdetailsByRoleIds();
      })
      .catch((err: any) => {
        VxeMessage('获取角色外权限保存异常', VxeNotifyType.error);
      });
  }
}

// 页面初次获取数据时默认选中第一个
function findUserList1() {
  showLoading.value = true;
  userList.length = 0;
  checkRoles.arr.length = 0;
  const url = '/api/user/getUserPageList';
  proxy.$http
    .get(url, { params: { pageIndex: page.currentPage, pageSize: page.pageSize } })
    .then((res: any) => {
      userList.push(...res.data.records);
      page.totalResult = res.data.total;
      userInfo.id = userList[0].id;
      userInfo.userName = userList[0].username;
      userRowClick({
        row: userList[0],
        rowIndex: 0
      });
      userTable.value?.setCurrentRow(userList[0]);
      showLoading.value = false;
    })
    .catch((err: any) => {
      showLoading.value = false;
      VxeMessage('搜索用户列表失败', VxeNotifyType.error);
    });
}

// 要选中修改的哪一行数据
function findUserListSelect(rowIndex: any) {
  showLoading.value = true;
  userList.length = 0;
  checkRoles.arr.length = 0;
  const url = '/api/user/getUserPageList';
  proxy.$http
    .get(url, { params: { pageIndex: page.currentPage, pageSize: page.pageSize } })
    .then((res: any) => {
      userList.push(...res.data.records);
      page.totalResult = res.data.total;
      userInfo.id = userList[rowIndex].id;
      userInfo.userName = userList[rowIndex].username;
      userRowClick({
        row: userList[rowIndex],
        rowIndex: rowIndex
      });
      showLoading.value = false;
    })
    .catch((err: any) => {
      showLoading.value = false;
      VxeMessage('搜索用户列表失败', VxeNotifyType.error);
    });
  showLoading.value = false;
}

//查询搜索用户列表
function findUserList(userName = '') {
  showLoading.value = true;
  userList.length = 0;
  // checkRoles.arr.length = 0;
  const url = '/api/user/getUserPageList';
  proxy.$http
    .get(url, { params: { pageIndex: page.currentPage, pageSize: page.pageSize } })
    .then((res: any) => {
      userList.push(...res.data.records);
      page.totalResult = res.data.total;
      findRoleList();
      if (userName) {
        let index = userList.findIndex((item) => item.username === userName);
        userRowClick({
          row: userList[index],
          rowIndex: index
        });
      }
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
  showLoading.value = true;
}

// 回车查询
function keyupEnter(e: any) {
  if (e.$event.code == 'Enter') {
    handleSearch(form.searchValue);
  }
}

//获取所有角色信息
function findRoleList() {
  showLoading.value = true;
  roleList.length = 0;
  const url = '/api/sys/findRoleList';
  proxy.$http
    .get(url)
    .then((res: any) => {
      if (roleList.length === 0) {
        roleList.push(...res.data.roleList);
      }
    })
    .catch((err: any) => {
      showLoading.value = false;
      VxeMessage('获取所有角色信息失败', VxeNotifyType.error);
    });
  showLoading.value = false;
}

function findOrgTree() {
  orgList.length = 0;

  const url = '/api/sys/findOrgTree';
  proxy.$http
    .get(url)
    .then((res: any) => {
      if (res.status.code !== 1) {
        proxy.$alert(res.status.msg, '提示');
      } else {
        orgList.push(...res.data.orgTree);
      }
    })
    .catch((err: any) => {
      VxeMessage('获取机构失败', VxeNotifyType.error);
    });
}

function findDeptTree() {
  deptList.length = 0;
  const url = '/api/sys/findDeptTree';
  const obj = { orgId: form.orgId, orgName: form.orgName };
  proxy.$http
    .get(url, { params: obj })
    .then((res: any) => {
      if (res.status.code !== 1) {
        VxeMessage('获取部门失败', VxeNotifyType.error);
      } else {
        deptList.push(...res.data.deptList);
        // this.setCurDeptTreeNode(this.userForm.deptId);
      }
    })
    .catch((err: any) => {
      proxy.$alert(err, '提示');
    });
}

function handleOrgNodeClick(data: any) {
  form.orgId = data.id;
  form.orgName = data.name;
  form.deptId = '';
  form.deptName = '';
  findDeptTree();
  const selectOrgRef: any = proxy.$refs['selectOrgRef'];
  selectOrgRef.blur();
}

function handleDeptNodeClick(data: any) {
  form.deptId = data.id;
  form.deptName = data.name;
  const selectDeptRef: any = proxy.$refs['selectDeptRef'];
  selectDeptRef.blur();
}

function handleDeptClear() {
  form.deptId = '';
  form.deptName = '';
  const treeName = 'deptTreeRef';
  const tree: any = proxy.$refs[treeName];
  tree.setCurrentKey(null);
}

// 查询/刷新
function handleSearch(row: any) {
  showLoading.value = true;
  userList.length = 0;
  const url = '/api/user/getUserPageList';
  proxy.$http
    .get(url, { params: { pageIndex: page.currentPage, pageSize: page.pageSize, keywords: row } })
    .then((res: any) => {
      userList.push(...res.data.records);
      page.totalResult = res.data.total;
      showLoading.value = false;
    })
    .catch((err: any) => {
      showLoading.value = false;
      VxeMessage('查询刷新失败', VxeNotifyType.error);
    });
}

// 保存左侧用户部分信息列表
async function saveList() {
  saveLoading.value = true;
  let $table = proxy.$refs.userTable;
  let changeindex = ref('0');
  if ($table) {
    const updateRecords = await $table.getUpdateRecords().filter((p: any) => {
      return p.id !== '';
    });
    // 修改保存
    updateRecords.forEach((e: any) => {
      // userList.length = 0;
      roleList.length = 0; //所有角色
      // checkRoles.arr.length = 0;//选中角色
      const url = '/api/user/editUserInfo';
      const user = {
        id: e.id,
        username: e.username,
        realname: e.realname,
        tel: e.tel,
        email: e.email,
        inputCode: e.inputCode,
        roleIds: checkRoles.arr,
        enable: e.enable
      };
      proxy.$http
        .post(url, user)
        .then((res: any) => {
          if (res.status.code === 1) {
            VxeMessage('修改用户成功', VxeNotifyType.success);
          }
          // findUserList(); //调用批量修改接口，最后只进行一次重新获取用户列表
          resetForm(currentUser);
        })
        .catch((err: any) => {
          VxeMessage('修改用户失败', VxeNotifyType.error);
        });
      let getUserList = userList.filter((item: any, index: any) => {
        if (item.id === e.id) {
          changeindex.value = index;
          return true; //返回true表示满足条件，保留该项
        } else {
          return false; //返回false表示不满足条件，过滤掉该项
        }
      });
    });
    setTimeout(() => {
      findRoleList(); //重新获取角色信息
      findUserListSelect(changeindex.value);
      saveLoading.value = false;
    }, 500);
  }
}

// 重置
function resetForm(row: any) {
  if (IsEmpty(row)) {
    clearForm();
    return;
  }
  form.id = null;
  form.username = '';
  form.realname = '';
  form.userMode = '';
  form.password = '';
  form.tel = '';
  form.email = '';
  form.inputCode = '';
  (form.empowerNum = ''), (form.enable = '1');
  form.initializer = '';
  form.orgId = '';
  form.orgName = '';
  form.deptId = '';
  form.deptName = '';
  form.roles = [];
  form.hisEmployeeId = '';
  form.hisEmployeeCode = '';
  form.searchValue = '';
  form.isTestDoctor = 0;
  form.isChkDoctor = 0;
  checkRoles.arr = [];
  findRoleList(); //获取所有的角色信息

  const treeName = 'orgTreeRef';
  const tree: any = proxy.$refs[treeName];
  tree.setCurrentKey(null);
  deptList.length = 0;
}

// 用户名正则校验
function validateUserName({ itemValue }: any) {
  const reg = /^[A-Za-z0-9]+$/;
  if (itemValue && !reg.test(itemValue)) {
    return new Error('用户名为数字和英文字母组合');
  }
}
// 用户名改变  @blur="userNameChange" 自动生成邮箱(废弃)
function userNameChange() {
  form.email = IsEmpty(form.email) ? form.username + '@limp.ltd' : form.email;
}

// 点击当前行// 行点击事件(需要调试)
async function userRowClick({ row, rowIndex }: any) {
  if (IsEmpty(row)) {
    currentUser = {} as any;
    return;
  }

  // let $Xtable = proxy.$refs.userTable;
  // $Xtable.setCurrentRow(row);
  await getEmployeeByUserId(row);

  currentRowIndex = rowIndex;
  currentUser = row;
  (proxy.$refs.userTable as any).setCurrentRow(row);
  userInfo.id = row.id;
  userInfo.userName = row.username;
  modules.length = 0;
  await getSysUserAuthdetailsByRoleIds();
  await findCheckList();
  await findcheckInstrSetupList();
  findUserDepartmentList();
  findCriUserVsDeptList();
}

// ---------------------------------------------------
//**判断为空*/
function IsEmpty(value: any) {
  if (value === undefined || value === '' || value === null) {
    return true;
  }
  if (JSON.stringify(value) === '{}') {
    return true;
  }
  return false;
}

// 根据id获取用户单条信息
function getEmployeeByUserId(user: any) {
  checkRoles.arr.length = 0;
  const url = '/api/user/findUserSimple';
  proxy.$http
    .get(url, { params: { id: user.id } })
    .then((res: any) => {
      form.id = res.data.user.id;
      form.username = res.data.user.username;
      form.realname = res.data.user.realname;
      form.userMode = res.data.user.userMode;
      form.password = res.data.user.password;
      form.orgId = res.data.user.orgId;
      form.orgName = res.data.user.orgName;
      form.deptId = res.data.user.deptId;
      form.deptName = res.data.user.deptName;
      form.tel = res.data.user.tel;
      form.email = res.data.user.email;
      form.inputCode = res.data.user.inputCode;
      form.empowerNum = res.data.user.empowerNum;
      form.initializer = res.data.user.initializer;
      form.enable = res.data.user.enable;
      form.hisEmployeeId = res.data.user.hisEmployeeId;
      form.hisEmployeeCode = res.data.user.hisEmployeeCode;
      form.searchValue = '';
      form.isTestDoctor = res.data.user.isTestDoctor ? res.data.user.isTestDoctor : 0;
      form.isChkDoctor = res.data.user.isChkDoctor ? res.data.user.isChkDoctor : 0;
      res.data.user.roles.forEach((item: any) => {
        checkRoles.arr.push(item.roleId + '');
        roleNames.push(item.roleName);
      });
      form.roles = checkRoles.arr;
      setCurOrgTreeNode(form.orgId);
      findDeptTree();
    })
    .catch((err: any) => {
      // VxeMessage('获取用户员工报错', VxeNotifyType.error);
    });
}

// 光标定位在指定字典分类上
function setCurOrgTreeNode(nodeId: any) {
  proxy.$nextTick(() => {
    const treeName = 'orgTreeRef';
    const tree: any = proxy.$refs[treeName];
    tree.setCurrentKey(nodeId);
  });
}

function getCainit() {
  let cert = [];
  let userList = security.SOF_GetUserList();
  console.log(userList);
  cert = userList.split('&&&');
  if (cert.length > 0) {
    let signCert = security.SOF_ExportUserCert(cert[0]);
    console.log(signCert);
    //获取证书序列号
    let zsxlh = security.SOF_GetCertInfo(signCert, 2);
    console.log(zsxlh);
    form.initializer = zsxlh;
  }
}

// 新建用户档案
function addUser() {
  currentUser = {};
  userInfo.id = '';
  currentRowIndex = 0;
  resetForm(currentUser);
  checkRptGroupList.length = 0;
  checkInstrSetupList.length = 0;
  (proxy.$refs.userTable as any).clearCurrentRow();
  modules.length = 0; //清空右侧盒子
}

// 保存
function save(formName: any) {
  let $el = proxy.$refs.userForm;
  let rightChangeIndex = ref(0);
  if (!$el) return;
  $el.validate((valid: any) => {
    if (!valid) {
      return false;
    }
    const $form = proxy.$refs.userForm;
    saveLoading.value = true;
    if ($form) {
      if (form.id == '' || form.id == null || form.id == undefined) {
        // 新增用户
        const url = '/api/user/addUserInfo';
        const user = {
          username: form.username,
          realname: form.realname,
          userMode: form.userMode,
          orgId: form.orgId,
          deptId: form.deptId,
          tel: form.tel,
          email: form.email,
          inputCode: form.inputCode,
          empowerNum: form.empowerNum,
          initializer: form.initializer,
          roleIds: checkRoles.arr,
          enable: form.enable,
          hisEmployeeId: form.hisEmployeeId,
          hisEmployeeCode: form.hisEmployeeCode,
          isTestDoctor: form.isTestDoctor,
          isChkDoctor: form.isChkDoctor
        };
        proxy.$http
          .post(url, user)
          .then((res: any) => {
            VxeMessage('新增用户成功', VxeNotifyType.success);
            modules.length = 0;
            rightChangeIndex.value = userList.findIndex((item) => item == currentRowIndex);
            findUserList(form.username);
          })
          .catch((err: any) => {
            VxeMessage('新增用户失败', VxeNotifyType.error);
            findUserList();
          });
      } else {
        // 修改用户
        const url = '/api/user/editUserInfo';
        const user = {
          id: form.id,
          username: form.username,
          realname: form.realname,
          userMode: form.userMode,
          orgId: form.orgId,
          deptId: form.deptId,
          tel: form.tel,
          email: form.email,
          inputCode: form.inputCode,
          empowerNum: form.empowerNum,
          initializer: form.initializer,
          roleIds: checkRoles.arr,
          enable: form.enable,
          hisEmployeeId: form.hisEmployeeId,
          hisEmployeeCode: form.hisEmployeeCode,
          isTestDoctor: form.isTestDoctor,
          isChkDoctor: form.isChkDoctor
        };
        proxy.$http
          .post(url, user)
          .then((res: any) => {
            VxeMessage('修改用户成功', VxeNotifyType.success);
            let getUserList = userList.filter((item: any, index: any) => {
              if (index === currentRowIndex) {
                rightChangeIndex.value = index;
                return true; //返回true表示满足条件，保留该项
              } else {
                return false; //返回false表示不满足条件，过滤掉该项
              }
            });
            findUserListSelect(rightChangeIndex.value);
          })
          .catch((err: any) => {
            VxeMessage('修改用户失败', VxeNotifyType.error);
          });
      }
      saveLoading.value = false;
    }
  });
}

// 清空右侧表单
function clearForm() {
  form.id = null;
  form.username = '';
  form.realname = '';
  form.password = '';
  form.tel = '';
  form.email = '';
  form.inputCode = '';
  form.empowerNum = '';
  form.initializer = '';
  form.enable = '1';
  form.roles = [];
  form.hisEmployeeId = '';
  form.hisEmployeeCode = '';
  form.searchValue = '';
  checkRoles.arr.length = 0;
  form.orgId = '';
  form.orgName = '';
  form.deptId = '';
  form.deptName = '';
  form.isTestDoctor = 0;
  form.isChkDoctor = 0;
  const treeName = 'orgTreeRef';
  const tree: any = proxy.$refs[treeName];
  tree.setCurrentKey(null);
  deptList.length = 0;
}

// -------------------------------------------------------------

// 重置密码
function resetPassword() {
  const selectRows = (proxy.$refs.userTable as any).getCheckboxRecords();
  if (selectRows.length > 1) {
    VxeMessage('一次只可选择重置一条数据', VxeNotifyType.warning);
    return;
  }

  if (selectRows.length <= 0) {
    VxeMessage('请勾选需要重置密码的用户', VxeNotifyType.warning);
    return;
  } else {
    resetPsdModal.value = true;
  }
}

// 取消打开重置密码弹框
function hidePsdModal() {
  let el = proxy.$refs.formPwdRef;
  // if (!$el) return;
  if (el) {
    el.clearValidate();
  }
  resetPsdModal.value = false;
  (formPwd.oldPassword = ''), (formPwd.newPassword = '');
  formPwd.repeatPassword = '';
}

// 保存新密码
function saveNewPassword() {
  let el = proxy.$refs.formPwdRef;
  // if (!$el) return;
  el.validate((valid: any) => {
    if (!valid) {
      return false;
    }
    const $table = (proxy.$refs.userTable as any).getCheckboxRecords();
    let getId = $table[0].id;
    // 选择了用户，密码未填
    if (formPwd.newPassword !== formPwd.repeatPassword) {
      VxeMessage('新密码与重复输入的新密码二者不一致', VxeNotifyType.warning);
      return;
    }
    if (IsEmpty(formPwd.newPassword) || IsEmpty(formPwd.repeatPassword)) {
      VxeMessage('密码不可为空', VxeNotifyType.warning);
      return;
    } else {
      const url = '/api/user/changePassword';
      const changePassword = {
        id: getId,
        username: $table[0].username,
        oldPwd: formPwd.oldPassword,
        newPwd: formPwd.newPassword,
        repeatPwd: formPwd.repeatPassword,
        changeType: 2
      };
      proxy.$http
        .post(url, changePassword)
        .then((res: any) => {
          if (res.status.code === 15) {
            VxeMessage('旧密码输入错误', VxeNotifyType.error);
          } else {
            VxeMessage('密码重置成功', VxeNotifyType.success);
            resetPsdModal.value = false;
          }
        })
        .catch((err: any) => {
          resetPsdModal.value = false;
          (proxy as any).$XModal.message({
            content: '密码重置失败的catch',
            status: 'warning'
          });
        });
    }
  });
}

// 删除数据
function handleDelete() {
  const selectRows = (proxy.$refs.userTable as any).getCheckboxRecords();
  if (selectRows.length > 1) {
    VxeMessage('一次只可选择删除一条数据', VxeNotifyType.warning);
    return;
  }
  if (selectRows.length <= 0) {
    VxeMessage('请选择需要删除的用户', VxeNotifyType.warning);
    return;
  } else {
    proxy
      .$confirm('确定删除此条用户数据？', '提示', {
        cancelButtonClass: 'cancel-button',
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
      .then(() => {
        selectRows.forEach(() => {
          const url = '/api/user/deleteUserById';
          proxy.$http
            .post(url, selectRows[0])
            .then((res: any) => {
              if (res.status.code != 1) {
                VxeMessage('删除用户失败', VxeNotifyType.error);
              } else {
                VxeMessage('删除用户成功', VxeNotifyType.success);
                findUserList();
                clearForm();
              }
            })
            .catch((err: any) => {
              VxeMessage('删除用户异常', VxeNotifyType.error);
            });
        });
      });
  }
}

// 回车切换输入框焦点
function enterEvent(row, rowIndex, column) {
  const $table = proxy.$refs.userTable as any;
  const fieldArr = Object.keys($table.fullColumnFieldData);
  let index = fieldArr.indexOf(column.field);
  let $rowIndex = rowIndex;
  // 当前为最后一单元格
  if (index === fieldArr.length - 1) {
    // 最后一行的最后一个单元格，取消切换
    if (rowIndex === proxy.userList.length - 1) {
      return;
    } else {
      // 跳转到下一行的第一个单元格
      $rowIndex++;
      index = 0;
    }
  } else {
    // 跳转到下一个单元格
    index++;
  }
  const newData = proxy.userList[$rowIndex];
  $table.setEditCell(newData, fieldArr[index]);
  proxy.$nextTick(() => {
    setTimeout(() => {
      // 如果有滚动条，滚动到对应的行或列
      $table.scrollToRow(newData);
      $table.scrollToColumn(fieldArr[index]);
    }, 50);
  });
}

function getEmployeeList() {
  employeeModal.value = true;
  employeeList.length = 0;
  findDataList();
}
// 查找员工列表
function findDataList() {
  importUserLoading.value = true;
  const url = '/api/sys/hisEmployee/finAllHisEmployeeList';
  proxy.$http
    .get(url)
    .then((res: any) => {
      if (res.data.length != 0) {
        employeeList.push(...res.data);
      }
      importUserLoading.value = false;
    })
    .catch((err: any) => {
      VxeMessage('搜索用户列表失败', VxeNotifyType.error);
      importUserLoading.value = false;
    });
}

// 批量导入数据
function importEmployee() {
  const selectRows = (proxy.$refs.employeeTable as any).getCheckboxRecords();
  if (selectRows.length > 0) {
    let employeeIds = reactive([]);
    employeeIds.push(
      ...selectRows.map((element) => {
        return element.id;
      })
    );
    const url = '/api/user/importUserByEmploy';
    const importObj = {
      roleId: null,
      employeeIds: employeeIds
    };
    proxy.$http
      .post(url, importObj)
      .then((res: any) => {
        employeeModal.value = false;
        findUserList();
      })
      .catch((err: any) => {
        (proxy as any).$XModal.message({
          content: err,
          status: 'warning'
        });
      });
  }
}

// 点击组件表格行
function SelectRowClick(row) {
  form.hisEmployeeCode = row.code;
}
// 清空组件输入框
function clearValueHandler() {
  form.hisEmployeeCode = '';
}
// 键盘事件删除输入框文字
function sliceHandler() {
  let newStr = form.hisEmployeeCode.slice(0, -1);
  form.hisEmployeeCode = newStr;
}

function autoInputCode() {
  form.inputCode = funBdsJsResult('firstPinYinFun', form.realname);
}

// 设置全选(报告单元)
function selectAllSelect() {
  checkRptGroupList.length = 0;
  let allItem = rptGroupList.map((item) => item.rptGroupName);
  checkRptGroupList.push(...allItem); //把所有的名字放进去

  let userInfoItem = [];
  rptGroupList.forEach((item) => {
    let obj = {
      id: '',
      userId: userInfo.id,
      rptGroupId: item.id
    };
    userInfoItem.push(obj);
  });

  const url = '/api/userRptGroup/addBatchSysUserRptGroup';
  proxy.$http
    .post(url, userInfoItem)
    .then((res) => {
      if (res.status.code !== 1) {
        VxeMessage('添加报告单元失败！', VxeNotifyType.error);
      } else {
        VxeMessage('添加报告单元成功！', VxeNotifyType.success);
      }
    })
    .catch((err) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}

// 取消全选(报告单元)
function clearAllSelect() {
  // checkRptGroupList.length = 0;
  const url = '/api/userRptGroup/deleteSysUserRptGroup';
  proxy.$http
    .post(url, { userId: userInfo.id })
    .then((res: any) => {
      if (res.status.code !== 1) {
        VxeMessage('删除报告单元失败！', VxeNotifyType.error);
      } else {
        checkRptGroupList.length = 0;
        VxeMessage('删除报告单元成功！', VxeNotifyType.success);
      }
    })
    .catch((err: any) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}

// 设置全选(检验仪器)
function selectAllSelect1() {
  checkInstrSetupList.length = 0;
  checkInstrSetupList.push(...instrSetupList.map((item) => item.instrName));

  let userInfoItem = [];
  instrSetupList.forEach((item) => {
    let obj = {
      id: '',
      userId: userInfo.id,
      instrSetupId: item.id
    };
    userInfoItem.push(obj);
  });

  const url = '/api/userInstrSetup/addBatchUserInstrSetUp';
  proxy.$http
    .post(url, userInfoItem)
    .then((res) => {
      if (res.status.code !== 1) {
        VxeMessage('添加检验仪器失败！', VxeNotifyType.error);
      } else {
        VxeMessage('添加检验仪器成功！', VxeNotifyType.success);
      }
    })
    .catch((err) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}

// 取消全选(检验仪器)
function clearAllSelect1() {
  const url = '/api/userInstrSetup/deleteUserInstrSetUp';
  proxy.$http
    .post(url, { userId: userInfo.id })
    .then((res: any) => {
      if (res.status.code !== 1) {
        VxeMessage('删除仪器失败！', VxeNotifyType.error);
      } else {
        VxeMessage('删除仪器成功！', VxeNotifyType.success);
        checkInstrSetupList.length = 0;
      }
    })
    .catch((err: any) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}

/**电子签名 */
function signatureClick() {
  if (IsEmpty(userInfo.id)) {
    setTimeout(() => {
      signatureClick();
    }, 50);
    return;
  }
  signatureUserRef.value?.init(userInfo);
}
/**保存用户信息 */
function saveUserInfo() {
  const url = '/api/user/onlyEditUser';
  proxy.$http
    .post(url, form)
    .then((res: any) => {
      if (res.status.code !== 1) {
        VxeMessage('修改失败！', VxeNotifyType.error);
      } else {
        VxeMessage('修改成功！', VxeNotifyType.success);
      }
    })
    .catch((err: any) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}

//新功能
let showDialog = ref(false); //添加弹框展示状态
let showUserVsDeptDialog = ref(false); //添加弹框展示状态

let qloading = ref(false); //右侧质控表格加载+刷新
let userDepartmentList: any = reactive([]); //右侧质控项目表格数据
let userVsDeptList: any = reactive([]); //右侧质控项目表格数据
let orgDeptList: any = reactive([]);
let orgUserVsDeptList: any = reactive([]);
let searchDeptForm = reactive({
  searchValue: ''
});

let lloading = ref(false); //右侧质控表格加载+刷新

// 回车查询
function keyupDeptEnter(e: any) {
  if (e.$event.code == 'Enter') {
    findOrgDeptList2();
  }
}
// 回车查询
function keyupUserDeptEnter(e: any) {
  if (e.$event.code == 'Enter') {
    findUserVsOrgDeptList();
  }
}
async function findOrgDeptList2() {
  lloading.value = true;
  orgDeptList.length = 0; //放入数据前清空数据

  const url = '/api/sys/findDepartmentList';
  proxy.$http
    .get(url, { params: { keywords: searchDeptForm.searchValue } })
    .then((res: any) => {
      orgDeptList.push(...res.data.deptList);
      const itemDictIds = userDepartmentList.map((m) => m.deptId);
      const ilist = orgDeptList.filter((p: any) => itemDictIds.includes(p.id));
      const $table = proxy.$refs.labItemTableRef;
      $table.setCheckboxRow(ilist, true);
      lloading.value = false;
    })
    .catch((err: any) => {
      lloading.value = false;
      VxeMessage('获取所有部门选项(下拉框)失败', VxeNotifyType.error);
    });
}

async function findUserVsOrgDeptList() {
  lloading.value = true;
  orgUserVsDeptList.length = 0; //放入数据前清空数据

  const url = '/api/sys/findDepartmentList';
  proxy.$http
    .get(url, { params: { keywords: searchDeptForm.searchValue } })
    .then((res: any) => {
      orgUserVsDeptList.push(...res.data.deptList);
      const itemDictIds = userVsDeptList.map((m) => m.deptId);
      const ilist = orgUserVsDeptList.filter((p: any) => itemDictIds.includes(p.id));
      const $table = proxy.$refs.criUserVsDeptTableRef;
      $table.setCheckboxRow(ilist, true);
      lloading.value = false;
    })
    .catch((err: any) => {
      lloading.value = false;
      VxeMessage('获取所有部门选项(下拉框)失败', VxeNotifyType.error);
    });
}

// 获取所有科室
async function findOrgDeptList() {
  lloading.value = true;
  orgDeptList.length = 0; //放入数据前清空数据

  const url = '/api/sys/findDepartmentList';
  proxy.$http
    .get(url, { params: {} })
    .then((res: any) => {
      orgDeptList.push(...res.data.deptList);
      const itemDictIds = userDepartmentList.map((m) => m.deptId);
      const ilist = orgDeptList.filter((p: any) => itemDictIds.includes(p.id));
      const $table = proxy.$refs.labItemTableRef;
      $table.setCheckboxRow(ilist, true);
      lloading.value = false;
    })
    .catch((err: any) => {
      VxeMessage('获取所有部门选项(下拉框)失败', VxeNotifyType.error);
      lloading.value = false;
    });
}
// 获取所有科室
async function findOrgDeptListByUser() {
  lloading.value = true;
  orgUserVsDeptList.length = 0; //放入数据前清空数据

  const url = '/api/sys/findDepartmentList';
  proxy.$http
    .get(url, { params: {} })
    .then((res: any) => {
      orgUserVsDeptList.push(...res.data.deptList);
      lloading.value = false;
    })
    .catch((err: any) => {
      VxeMessage('获取所有部门选项(下拉框)失败', VxeNotifyType.error);
      lloading.value = false;
    });
}
function findUserDepartmentList() {
  if (IsEmpty(currentUser)) {
    VxeMessage('请选择部门', VxeNotifyType.error);
  } else {
    qloading.value = true;
    userDepartmentList.length = 0; //放入数据前清空数据
    const url = '/api/userDepartment/findUserDepartmentList';
    proxy.$http
      //注意此处的数据条数
      .get(url, {
        params: { userId: currentUser.id }
      })
      .then((res: any) => {
        userDepartmentList.push(...res.data);
        qloading.value = false;
      })
      .catch((err: any) => {
        qloading.value = false;
        VxeMessage('获取右侧获取质控项目表格数据异常', VxeNotifyType.error);
      });
  }
}
function findCriUserVsDeptList() {
  if (IsEmpty(currentUser)) {
    VxeMessage('请选择用户', VxeNotifyType.error);
  } else {
    qloading.value = true;
    userVsDeptList.length = 0; //放入数据前清空数据
    const url = '/lis/cri/userVsDept/findCriUserDeptList';
    proxy.$http
      //注意此处的数据条数
      .get(url, {
        params: { username: currentUser.username }
      })
      .then((res: any) => {
        userVsDeptList.push(...res.data);
        qloading.value = false;
      })
      .catch((err: any) => {
        qloading.value = false;
        VxeMessage('获取用户对照科室数据异常', VxeNotifyType.error);
      });
  }
}
// 删除按钮
function handleUserDepartmentDelete() {
  const sltQcItems = (proxy.$refs.qcItemTableRef as any).getCheckboxRecords();
  if (!(sltQcItems.length > 0)) {
    VxeMessage('请勾选要删除的数据', VxeNotifyType.info);
  } else {
    proxy
      .$confirm('确定要删除当前勾选的数据？', '提示', {
        cancelButtonClass: 'cancel-button',
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
      .then(() => {
        const data = { sysUserDepartmentList: sltQcItems };
        const url = '/api/userDepartment/batchDeleteUserDepartmentList';
        proxy.$http
          .post(url, data)
          .then((res: any) => {
            findUserDepartmentList(); // 获取检验仪器表格数据
            VxeMessage(res.status.msg, VxeNotifyType.success);
          })
          .catch((err: any) => {
            VxeMessage(err, VxeNotifyType.error);
          });
      })
      .catch((err: any) => {
        // VxeMessage(err, VxeNotifyType.error);
      });
  }
}
// 删除按钮
function handleUserVsDepartmentDelete() {
  const sltQcItems = (proxy.$refs.userVsDeptTable as any).getCheckboxRecords();
  if (!(sltQcItems.length > 0)) {
    VxeMessage('请勾选要删除的数据', VxeNotifyType.info);
  } else {
    proxy
      .$confirm('确定要删除当前勾选的数据？', '提示', {
        cancelButtonClass: 'cancel-button',
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
      .then(() => {
        const url = '/lis/cri/userVsDept/batchDeleteUserVsDeptList';
        proxy.$http
          .post(url, sltQcItems)
          .then((res: any) => {
            findCriUserVsDeptList(); // 获取检验仪器表格数据
            VxeMessage(res.status.msg, VxeNotifyType.success);
          })
          .catch((err: any) => {
            VxeMessage(err, VxeNotifyType.error);
          });
      })
      .catch((err: any) => {
        // VxeMessage(err, VxeNotifyType.error);
      });
  }
}

// 添加按钮
function addUserDepartDialog() {
  if (IsEmpty(currentUser)) {
    VxeMessage('请选择用户', VxeNotifyType.error);
  } else {
    findOrgDeptList();
    showDialog.value = true;
  }
}
// 添加按钮
function addUserVsDeptDialog() {
  if (IsEmpty(currentUser)) {
    VxeMessage('请选择用户', VxeNotifyType.error);
  } else {
    findOrgDeptListByUser();
    showUserVsDeptDialog.value = true;
  }
}

function closeDialog() {
  searchDeptForm.searchValue = '';
  showDialog.value = false;
}
function closeUserVsDeptDialog() {
  searchDeptForm.searchValue = '';
  showUserVsDeptDialog.value = false;
}

function saveBacthQcItem() {
  const selectRows = (proxy.$refs.labItemTableRef as any).getCheckboxRecords();
  if (selectRows.length > 0) {
    const addQcItemList = [];
    for (const sltRow of selectRows) {
      const qcitem = userDepartmentList.find((qc: any) => qc.deptId == sltRow.id);
      if (IsEmpty(qcitem)) {
        const addQcItem = {
          deptId: sltRow.id,
          deptCode: sltRow.code,
          userId: currentUser.id
        };
        addQcItemList.push(addQcItem);
      }
    }
    if (addQcItemList.length > 0) {
      const data = { sysUserDepartmentList: addQcItemList };
      const url = '/api/userDepartment/batchAddSysUserDepartList';
      proxy.$http
        .post(url, data)
        .then((res: any) => {
          findUserDepartmentList(); // 获取检验仪器表格数据
          VxeMessage(res.status.msg, VxeNotifyType.success);
        })
        .catch((err: any) => {
          VxeMessage(err, VxeNotifyType.error);
        });
    } else {
      VxeMessage('请选择要添加的数据', VxeNotifyType.error);
    }
  }
  closeDialog();
}
function saveBacthUserVsDept() {
  const selectRows = (proxy.$refs.criUserVsDeptTableRef as any).getCheckboxRecords();
  if (selectRows.length > 0) {
    const addQcItemList = [];
    for (const sltRow of selectRows) {
      const qcitem = userVsDeptList.find((qc: any) => qc.deptId == sltRow.id);
      if (IsEmpty(qcitem)) {
        const addQcItem = {
          deptId: sltRow.id,
          deptCode: sltRow.code,
          username: currentUser.username
        };
        addQcItemList.push(addQcItem);
      }
    }
    if (addQcItemList.length > 0) {
      const data = { sysUserDepartmentList: addQcItemList };
      const url = '/lis/cri/userVsDept/batchAddUserDeptList';
      proxy.$http
        .post(url, addQcItemList)
        .then((res: any) => {
          findCriUserVsDeptList(); // 获取检验仪器表格数据
          VxeMessage(res.status.msg, VxeNotifyType.success);
        })
        .catch((err: any) => {
          VxeMessage(err, VxeNotifyType.error);
        });
    } else {
      VxeMessage('请选择要添加的数据', VxeNotifyType.error);
    }
  }
  closeUserVsDeptDialog();
}

// 弹框 表格复选框(是否允许用户手动勾选)
function checCheckboxkMethod2({ row }: any) {
  const obj = userDepartmentList.filter((p: any) => {
    return p.deptId == row.id;
  });
  return obj.length == 0;
}

// 弹框 表格复选框 设置(是否显示复选框)
function showCheckboxkMethod2({ row }: any) {
  const obj = userDepartmentList.filter((p: any) => {
    // return p.itemDictId == row.id;
  });
  return obj.length == 0;
}
let defaultSelecteRowKeysByUser = reactive([]);
// 弹框 表格复选框(是否允许用户手动勾选)
function checCheckboxkMethod3({ row }: any) {
  defaultSelecteRowKeysByUser.length = 0;
  const obj = userVsDeptList.filter((p: any) => {
    defaultSelecteRowKeysByUser.push(p.deptId);
    return p.deptId == row.id;
  });
  return obj.length == 0;
}

// 弹框 表格复选框 设置(是否显示复选框)
function showCheckboxkMethod3({ row }: any) {
  const obj = userVsDeptList.filter((p: any) => {
    // return p.itemDictId == row.id;
  });
  return obj.length == 0;
}
</script>

<style lang="scss" scoped>
#userManage {
  height: 100%;

  .area {
    height: 100%;

    // 附加按钮间距
    .button-blue,
    .button-red {
      margin: 5px 0 5px 5px;
    }

    // 最左侧表格
    .leftTable {
      height: calc(100% - 40px - 32px);

      // :deep(.vxe-table--render-default) {
      //   height: calc(100% - 44px);
      // }
    }
    .rightTable {
      height: calc(100% - 40px);

      // :deep(.vxe-table--render-default) {
      //   height: calc(100% - 44px);
      // }
    }

    // 中间基本详情的复选框
    .el-form .el-checkbox {
      width: calc(50% - 40px);
      height: 30px;
      margin-left: 0;
      margin-top: 5px;
    }
    // 复选框最小宽度设置
    .min-width-checkbox {
      min-width: 120px;
    }

    // 右侧——基本信息
    .rightDetail {
      height: 100%;
      .rightContent {
        height: 100%;
        // padding: 0 10px;
        // .el-scrollbar {
        //   height: calc(100% - 40px);
        // }
        // :deep(.el-scrollbar__view) {
        //   height: 100%;
        // }
        .paneBox {
          padding: 0 10px;
        }
        // 空状态
        .el-empty {
          :deep(.el-empty__image) {
            position: absolute;
            top: 25%;
          }
          :deep(.el-empty__description) {
            position: absolute;
            top: 53%;
          }
        }
      }
    }

    // 重置密码
    .resetDialog {
      margin: 20px;
      .passwordInput {
        width: calc(100% - 100px);
        height: 35px;
      }
      .passwordThree {
        margin-top: 20px;
        span {
          margin-left: 43px;
        }
      }
      .passwordThreeS {
        .passwordInput {
          width: calc(100% - 83px);
        }
        margin-top: 20px;
        margin-left: 17px;
      }
    }
    // 导入用户
    :deep(.vxe-modal--box) {
      width: 800px;
      height: 500px;
      .el-scrollbar {
        height: 90%;
      }
      .importUser {
        width: 100%;
        height: 90%;
        .vxe-table {
          height: 98%;
        }
      }
      .importUserButton {
        margin-top: 10px;
      }
    }
  }
}

// 权限详情
.paneBox {
  justify-content: space-between;
  height: calc(100% - 39px);
  overflow: auto;

  :deep(.el-card__header) {
    padding: 10px;
    padding-left: 10px;
    font-size: 16px;
    font-weight: 500;
  }

  .box-card {
    margin-top: 10px;
    height: auto;
    :deep(.el-card__body) {
      padding: 0 !important;
    }
    &:nth-child(1) {
      margin-top: 0;
    }

    .detailBox {
      padding: 2px 5px;
      height: 100%;
    }
    // 权限详情大盒子
    .detailBox {
      height: 100%;
      // 菜单列表盒子
      .menuBox {
        width: 100%;
        height: 100%;

        .checkItem {
          border-radius: 20px;
          .el-checkbox {
            padding: 0 10px;
            text-align: center;
          }
        }
      }
      // 功能列表盒子
      .pointBox {
        width: 100%;
        height: 100%;
        .checkItem {
          .el-checkbox {
            padding: 0 10px;
            text-align: center;
          }
        }
      }
    }
  }
}

// 二级菜单外层盒子
.twoMenuTag {
  margin-left: 15px;
  display: inline-block;
}
.twoMenuTagDialog {
  margin-left: 5px;
}
.el-dialog .el-checkbox {
  margin-right: 5px;
}
.tagtitle1 {
  margin-left: 10px;
  margin-bottom: 10px;
}
.tagtitle2 {
  margin-left: 10px;
  margin-bottom: 10px;
}
// 一级菜单
.tagBox {
  text-align: center;
  vertical-align: middle;
  padding-left: 22px;
  margin-bottom: 10px;
  margin-left: 10px;
  border-radius: 5px;
}
.DialogFirstTag {
  padding: 15px;
  font-size: 14px;
}
.tagboxborder {
  border: 1px solid #27b46b;
  color: #27b46b;
}
.dialogOnlyFirstMenu {
  border: 1px solid #27b46b;
  color: #27b46b;
  :deep(.el-checkbox__input.is-checked .el-checkbox__inner) {
    background-color: #27b46b;
    border-color: #27b46b;
  }
  :deep(.el-checkbox__input.is-checked + .el-checkbox__label) {
    color: #27b46b;
  }
}

.pointSelectBox {
  border: 1px solid #eabe7e;
  color: #eabe7e;
  :deep(.el-checkbox__input.is-checked .el-checkbox__inner) {
    background-color: #eabe7e;
    border-color: #eabe7e;
  }
  :deep(.el-checkbox__input.is-checked + .el-checkbox__label) {
    color: #eabe7e;
  }
}

.DiaTwoboxBorder {
  border: 1px solid #c8c9cc;
  color: #909399;
  :deep(.el-checkbox__input.is-checked .el-checkbox__inner) {
    background-color: #909399;
    border-color: #909399;
  }
  :deep(.el-checkbox__input.is-checked + .el-checkbox__label) {
    color: #909399;
  }
}

.tagBox:hover {
  cursor: pointer;
  .tagicon {
    opacity: 1;
  }
}

.twomenutagbgc {
  background-color: #f7f7f7;
}

//tag删除按钮
.tagicon {
  opacity: 0;
}

.tagBox1:hover {
  cursor: pointer;
  .tagicon {
    opacity: 1;
  }
}

// 功能列表tag
.tagBox1 {
  vertical-align: middle;
  margin-bottom: 10px;
  padding-left: 22px;
  margin-left: 11px;
  border-radius: 5px;
}

// 报告单元只做展示的tag
.UnitBox {
  margin: 15px;
  .el-checkbox {
    margin: 0 10px 10px 0;
  }
  .allSelectedBtns {
    margin-bottom: 10px;
    .vxe-button {
      border-radius: 5px;
    }
  }
}

.spec-checkbox {
  margin-top: 0 !important;
  height: 24px !important;
  line-height: 24px !important;
}
</style>
